import { NextFunction, Request, Response } from "express";

/**
 * Constructor
 *
 * @class BaseRoute
 */
export class BaseController {

  protected code: number;

  private message: string;
  private data:any;
 
  /**
   * Constructor
   *
   * @class BaseRoute
   * @constructor
   */
  constructor() {
    //initialize variables
    this.code = 0;
    this.message ="";
    this.data={};
  }
 

  /**
   * Render a page.
   *
   * @class BaseRoute
   * @method render
   * @param req {Request} The request object.
   * @param res {Response} The response object.
   * @param view {String} The view to render.
   * @param options {Object} Additional options to append to the view's local scope.
   * @return void
   */
  public render(req: Request, res: Response, view: string, options?: Object) {
    //add constants
    res.locals.BASE_URL = "/";

    // //add message
    // res.locals.message = this.message;

    // //add code
    // res.locals.code = this.code;

    // //add data
    // res.locals.data = this.data;

    //render view
    res.render(view, this.ResultMsg(options));
  }


  public json(req: Request, res: Response, view: string, options?: Object) { 
    res.json(this.ResultMsg(options));
  }


 
  public ResultMsg(options?: Object)
  {
     return {code:this.code,message:this.message,data:options};
  }
}